﻿#pragma once
#include <math.h>
#include <glm/glm.hpp>

namespace Kriko
{
    class AABB
    {
    public:
        AABB() : min(0), max(0) {}
        AABB(glm::vec3 min, glm::vec3 max) : min(min), max(max) {}

        bool IsNULL() const { return min.x == min.y == min.z == max.x == max.y == max.z; }
        glm::vec3 Extents() const { return max - min; }
        glm::vec3 Center() const { return (max - min) / 2.f + min; }
        void GrowToInclude(const glm::vec3& v)
        {
            min = glm::vec3(fmin(min[0], v[0]), fmin(min[1], v[1]), fmin(min[2], v[2]));
            max = glm::vec3(fmax(max[0], v[0]), fmax(max[1], v[1]), fmax(max[2], v[2]));
        }
        void GrowToInclude(const AABB& aabb)
        {
            min = glm::vec3(fmin(min[0], aabb.min[0]), fmin(min[1], aabb.min[1]), fmin(min[2], aabb.min[2]));
            max = glm::vec3(fmax(max[0], aabb.max[0]), fmax(max[1], aabb.max[1]), fmax(max[2], aabb.max[2]));
        }
    public:
        glm::vec3 min;
        glm::vec3 max;
    };
}